package sql;

import DataClass.OldInfo;
import packet.AccCheck;
import packet.SendOldInfo;
import packet.sendLocation;
import test.CAREGIVER;
import test.CareGiver2;
import test.OLDMANDETIAL;
import test.oldman;
import test.writeSql;

public class getPW {
	public void checkPw(String account, String pw) {
		 try {
		CAREGIVER[] db;
		CareGiver2 acc = new CareGiver2();
		String[][] aa = acc.selectPW(account);
		CAREGIVER obj = new CAREGIVER();
		db = obj.toObject(aa);

		// select老人
		int cId = db[0].getIdcaregiver();
		oldman a = new oldman();
		String[][] bb = a.selectCareToOld(cId);

		// OLDMANDETIAL obj2=new OLDMANDETIAL();
		// OLDMANDETIAL[]old;
		//
		// old=obj2.toObject(bb);
		// if (true) return;
		// for (OLDMANDETIAL oi : old) {
//		OldInfo f = new OldInfo();

		// f.id=oi.getIdoldman();
		// f.name=oi.getNameoldman();
		// f.tel=oi.getTeloldman();
		// q.oldlist.add(f);
		// }

		
		SendOldInfo q = new SendOldInfo();

		for (int i = 0; i < bb.length; i++) {
			int k = 0;
			// out.print(bb[i][k] + " ");
			OldInfo f = new OldInfo();
			f.id = Integer.parseInt(bb[i][k]);
			f.name = bb[i][k + 1];
			f.tel = bb[i][k + 3];
			q.addOldInfo(f);
		}
//		writeSql.lc.send(q);
		
		writeSql.lc.send(q);
		
		// if (true)return;
		// System.out.println(f.name+f.tel);

		AccCheck p = new AccCheck();

		if (pw.equals(db[0].getPasswordcaregiver())) {
			p.state = true;

		} else {
			p.state = false;

		}
		writeSql.lc.send(p);

		 } catch (Exception e) {
		 AccCheck err = new AccCheck();
		 err.state=false;		 
		 writeSql.lc.send(err);
		 }

	}
}
